/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-04-12
*/
package com.rzico.core.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.core.entity.SysIcon;
import com.rzico.core.entity.SysPvuvSummary;
import com.rzico.core.entity.SysUser;
import com.rzico.core.service.SysPvuvSummaryService;
import com.rzico.core.service.SysUserService;
import com.rzico.entity.Filter;
import com.rzico.entity.Pageable;
import com.rzico.entity.PageResult;
import com.rzico.core.entity.SysPvuvTravel;
import com.rzico.core.service.SysPvuvTravelService;
import com.rzico.util.IPUtils;
import cz.mallat.uasparser.OnlineUpdater;
import cz.mallat.uasparser.UASparser;
import cz.mallat.uasparser.UserAgentInfo;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.Api;
import com.rzico.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.*;

/**
 * 访问记录控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-04-12
 */
@Api(description = "访问记录接口")
@RestController
@RequestMapping("/admin/pvuv")
public class SysPvuvController extends BaseController {

    @Autowired
    private SysPvuvTravelService sysPvuvTravelService;

    @Autowired
    private SysPvuvSummaryService sysPvuvSummaryService;

    @Autowired
    private SysUserService sysUserService;

    /**
     * PUVU 访问统计
     *
     * @return
     */
    @ApiOperation("PUVU 访问统计")
    @GetMapping("/summary")
    @ApiImplicitParams({@ApiImplicitParam(name = "days", value = "统计天数0为当前，近7天为6", dataType = "Integer", allowMultiple = true, paramType = "query")})
    public CommResult<SysPvuvTravel> summary(Integer days) {
        Map<String, Object> params = new HashMap<String, Object>();
        SysUser sysUser = sysUserService.getCurrent();
        params.put("mchId", sysUser.getMchId());
        params.put("startDate", DateUtils.truncate(DateUtils.addDays(new Date(),-days),Calendar.DATE));
        params.put("endDate", new Date());

        List<Map<String,Object>> data = sysPvuvSummaryService.summary(params);
        return CommResult.success(data);
    }

}
